package logic;
public class ThreadMessages extends Thread {
	public Server server;
	public long duration;
	public ThreadMessages(Server server)
	{
		this.server=server;
		this.duration=10000;
	}
	public void run(){
		
		while(true)
		{
			for(int i =0; i<server.getStoredMessages().size();i++)
			{
				if(server.getStoredMessages().get(i).getDate()<System.currentTimeMillis()-duration)
				{
					server.getStoredMessages().remove(i);
					i--;
				}
			}
			for(int i =0; i<server.getPutchunkMessages().size();i++)
			{
				if(server.getPutchunkMessages().get(i).getDate()<System.currentTimeMillis()-duration)
				{
					server.getPutchunkMessages().remove(i);
					i--;
				}
			}
			for(int i =0; i<server.getPutchunkBlackList().size();i++)
			{
				if(server.getPutchunkBlackList().get(i).getDate()<System.currentTimeMillis()-duration)
				{
					server.getPutchunkBlackList().remove(i);
					i--;
				}
			}
			for(int i =0; i<server.getChunkMessage().size();i++)
			{
				if(server.getChunkMessage().get(i).getDate()<System.currentTimeMillis()-duration)
				{
					server.getChunkMessage().remove(i);
					i--;
				}
			}
			try {
				sleep(duration);
			} catch (InterruptedException e) {
				 
				//e.printStackTrace();
			}
		}
	}
}
